// -------------------------------------------------------------
// api: respool.create
// time: 2020-07-31
// author: minner
// -------------------------------------------------------------
exports['respool.create'] = obj_api = {
    '1.0': function (args, session, callback) {
        if (!session.account_id) {
            return callback(12, null, '会话已失效');
        }

        if (!args.respool_name || typeof args.respool_name != 'string') {
            return callback(11, null, '缺少参数(respool_name)');
        }
        if (!args.description || typeof args.description != 'string') {
            return callback(11, null, '缺少参数(description)');
        }
        if (args.auto_deploy) {
            if (!args.respool_api || typeof args.respool_api != 'string') {
                return callback(11, null, '缺少参数(respool_api)');
            }
            if (!args.respool_account || typeof args.respool_account != 'string') {
                return callback(11, null, '缺少参数(respool_account)');
            }
            if (!args.respool_password || typeof args.respool_password != 'string') {
                return callback(11, null, '缺少参数(respool_password)');
            }
        }
        let sql_insert = "INSERT INTO `deploy_respool`" +
            " (`respool_name`, `auto_deploy`, `respool_api`, `respool_account`, `respool_password`, `create_time`, `creator`, `status`, `description`)" +
            " VALUES (" +
            mysql.escape(args.respool_name) + ", " +
            (args.auto_deploy ? 1 : 0) + ", " +
            mysql.escape(args.respool_api) + ", " +
            mysql.escape(args.respool_account) + ", " +
            mysql.escape(args.respool_password) + ", '" +
            uim.dateTime() + "', " +
            session.account_id + ", '1', " +
            mysql.escape(args.description) + ")";

        uim.db_query(sql_insert, function (err, results, fields) {
            if (err) {
                return callback(6, null, '数据库查询出错：' + err);
            }
            callback(0, {
                respool_id: results.insertId,
            });
        });
    },

};
